using AiQiuQuan.Sport.Model.Models;
using AiQiuQuan.Sport.Core;
using AiQiuQuan.Sport.WebApi.Services;
using Microsoft.AspNetCore.Mvc;
using AiQiuQuan.Sport.Model.Enums;
using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.WebApi.Controllers
{
    /// <summary>
    /// 评论管理
    /// </summary>
    public class CommentController : ApiController
    {
        private readonly ICommentService _commentService;

        /// <summary>
        /// ctor
        /// </summary>
        public CommentController(
            ICommentService commentService)
        {
            _commentService = commentService;
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        [HttpPost("pagelist")]
        public async Task<UnaryResult<PageResult<CommentDto>>> PageListAsync(CommentPageReqestDto request)
        {
            var result = await _commentService.PageListAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="businessType">业务类型</param>
        /// <param name="id">评论id</param>
        [HttpGet("get")]
        public async Task<UnaryResult<CommentDto>> GetAsync([Required] BusinessTypeEnum businessType, [Required] Guid id)
        {
            var result = await _commentService.GetAsync(businessType, id);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 新增
        /// </summary>
        [HttpPost("add")]
        public async Task<UnaryResult> AddAsync(CommentAddDto model)
        {
            var result = await _commentService.AddAsync(model);
            return result;
        }
    }
}
